﻿using System;
using System.Collections.Generic;
using Localization;
using SinBiota.Model.Business.PersistenceServices.Interfaces;
using SinBiota.Model.Entities;
using SinBiota.Model.Exceptions;
using SinBiota.Model.Persistence.Repositories.Interfaces;

namespace SinBiota.Model.Business.PersistenceServices.Implementation
{
    public class InstitutionPersistenceServices : IInstitutionPersistenceServices
    {
        private readonly IInstitutionRepository _institutionRepository;

        public InstitutionPersistenceServices(IInstitutionRepository institutionRepository)
        {
            _institutionRepository = institutionRepository;
        }

        public Institution FindById(int id)
        {
            return _institutionRepository.FindById(id);
        }

        public IList<Institution> FindAll()
        {
            return _institutionRepository.FindAll();
        }

        public void Delete(Institution institution)
        {
            _institutionRepository.Delete(institution);
        }

        public void DeleteById(int id)
        {
            Delete(FindById(id));
        }
        public void Save(Institution institution)
        {
            if (FindByName(institution.Name) != null) throw new PersistenceException(Messages.InstitutionNameAlreadyExists + ". " + Messages.PleaseChooseDifferentName);
            _institutionRepository.Save(institution);
        }

        public void Update(Institution institution)
        {
            _institutionRepository.Update(institution);
        }

        public Institution FindByName(string name)
        {
            return _institutionRepository.FindByName(name);
        }

        public IList<Institution> FindByNameLike(string name)
        {
            return _institutionRepository.FindByNameLike(name);
        }
    }
}